package com.demon.auto.model.vo;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.demon.auto.model.dto.ClientConfigDto;
import com.demon.auto.model.entity.SignClientEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;

/**
 * 签到客户端
 *
 * @version 1.0
 * @author huangrz
 * @date 2025/02/21 11:46
 */
@Slf4j
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SignClientVo extends PageVo<SignClientEntity> {

    /**
     * 主键
     */
    private Long id;
    /**
     * 有效标识
     */
    private Boolean validFlag;
    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;
    /**
     * 修改人
     */
    private Long updateCode;
    /**
     * 创建人
     */
    private Long createCode;
    /**
     * 最后在线时间（心跳）
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime lastOnlineTime;
    /**
     * 自动签到时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime autoSignTime;

    /**
     * 是否启用
     */
    private Boolean openFlag;
    /**
     * 客户端名称
     */
    private String clientName;

    /**
     * 配置信息
     */
    private ClientConfigDto config;
    /**
     * 在线标识
     */
    private Boolean onlineFlag;
    /**
     * 客户端别名
     */
    private String alias;
    /**
     * 关联时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime relationTime;


    /**
     * 配置信息模糊搜索
     */
    private String configQuery;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime onlineTimeBegin;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime onlineTimeEnd;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTimeBegin;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTimeEnd;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTimeBegin;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTimeEnd;

    public SignClientVo setConfig(String configJson) {
        if (StringUtils.isBlank(configJson)) {
            return this;
        }

        try {
            this.config  = JSON.parseObject(configJson, ClientConfigDto.class);
        } catch (Exception e) {
            log.error("解析客户端配置信息异常！clientName:{}, configJson:{}", this.clientName, configJson, e);
        }
        return this;
    }

}
